/**
 * @param {ng.auto.IProvideService} $provide
 * @param {ng.IHttpProvider} $httpProvider
 */
function MyHttpInterceptor($provide, $httpProvider) {
  // register the interceptor as a service
  $provide.factory(
    "myHttpInterceptor",
    /**
     * @param {ng.IQService} $q
     * @param {unknown} dependency1
     * @param {unknown} dependency2
     * @returns {ng.IHttpInterceptor}
     */
    ($q, dependency1, dependency2) => ({
      // optional method
      request(config) {
        // do something on success
        return config;
      },

      // optional method
      requestError(rejection) {
        // do something on error
        // if (canRecover(rejection)) {
        //   return responseOrNewPromise
        // }
        return $q.reject(rejection);
      },

      // optional method
      response(response) {
        // do something on success
        return response;
      },

      // optional method
      responseError(rejection) {
        // do something on error
        // if (canRecover(rejection)) {
        //   return responseOrNewPromise
        // }
        return $q.reject(rejection);
      },
    }),
  );

  $httpProvider.interceptors.push("myHttpInterceptor");

  // alternatively, register the interceptor via an anonymous factory
  $httpProvider.interceptors.push(
    /**
     * @param {ng.IQService} $q
     * @param {unknown} dependency1
     * @param {unknown} dependency2
     * @returns {ng.IHttpInterceptor}
     */
    ($q, dependency1, dependency2) => ({
      request(config) {
        // same as above
        return config;
      },
      response(response) {
        // same as above
        return response;
      },
    }),
  );
}
